class EventEmitter {
    constructor() {
        _event = []
    }
    on = (evt, fn) => {
        if (typeof fn !== 'function') {
            throw TypeError('second param must be a function')
        }
        this._event[evt] || (this._event[evt] = []).push(fn)
    }
    once = (evt, fn) => {
        function exeFn () {
            fn.apply(this)
            this.off(evt, exeFn)
        }
        this.on(evt, exeFn)
    }
    emit = (evt, ...args) => {
        if (!this._event[evt]) return false
        let fns = this._event[evt]
        fns.forEach(fn => {
            fn.apply(args)
        });
        return true
    }
    off = (evt, fn) => {
        if (!fn) {
            this._event[evt].length = 0
        } else {
            let fns = this._event[evt]
            for (let i = 0; i < fns.length; i++) {
                if (fns[i] === fn || fns[i].fn === fn) {
                    fns.splice(i, 1)
                }
            }
        }
    }
    removeAllListener = (evt) => {
        if (evt) {
            this._event[evt].length = 0
        } else {
            this._event = []
        }
    }
}